var  Eg_url = sysConfig.urlConfig.eg_url;
var  Wz_url = sysConfig.urlConfig.wz_url;

$(function(){
    Addfrom();

    if (window.android != null && typeof (window.android) != "undefined") {
        window.android.callAndroidWebViewInitComplete();
    } else {
        alert(typeof (window.android));
    }



});
//初始化信息表
function Addfrom() {
    let PDth = "";
    let PDtd = '';
    for (let i = 1; i <= 50; i++) {
        PDtd += '<td><label>' + i + '<input type="checkbox" value=' + i + ' name="test"/></label></td>';
        PDth += '<th>' + i + '</th>'
    }
    $(".body .diplay4 .table_Frequency .table_nr table tr.th").html(PDth);

    for (let i = 1; i <= 7; i++) {
        $("#form_PDid .table_tab .table_left table").append('<tr id="trth' + i + '" class="main"><th style="position: relative;"><input id="text' + i + '" name="wzmc" type="text" onkeydown="ZWdataYFone(\'' + i + '\')" placeholder="输入植物名称" style="width: 84px; outline: none; background: #6CBCFE; border: 0"><input type="hidden" id="hiddentext' + i + '" name="wzdm"></th></tr>');
        $("#form_PDid .table_tab .table_nr table").append("<tr id='trtd" + i + "'>" + PDtd + "</tr>" + "<input type='hidden' value=''/>");
    }

    // 横排加
    $(".body .diplay4 .table_Frequency .plus_top").click(function () {
        // 横数
        var th_length = $('.body .diplay4 .table_Frequency .table_nr table tr th').length + 1;
        var transverse_th = '<th>' + th_length + '</th>';
        var transverse_td = '<td>' + th_length + '<input type="checkbox" valuer="' + th_length + '" name="test"/></td>';
        $(".body .diplay4 .table_Frequency .table_nr table tr:not(.th)").append(transverse_td);
        $(".body .diplay4 .table_Frequency .table_nr table .th").append(transverse_th);
    });

    // 植物名称
    let ADDth = $(".body .diplay4 .table_Frequency .table_left #trth1:first").html();
    let ADDtd = $(".body .diplay4 .table_Frequency .table_nr #trtd1:first").html();
    // 竖排加
    $(".body .diplay4 .table_Frequency .plus_bottom").click(function () {
        // 竖排
        var tr_length = $('.body .diplay4 .table_Frequency .table_nr table tr').length;
        $(".body .diplay4 .table_Frequency .table_tab .table_left table").append('<tr id="trth' + tr_length + '" class="main"><th style="position: relative;"><input id="text' + tr_length + '" type="text" onkeydown="ZWdataYFone(\'' + tr_length + '\')" placeholder="输入植物名称" style="width: 84px; outline: none; background: #6CBCFE; border: 0"><input type="hidden" id="hiddentext' + tr_length + '"></th></tr>');
        $(".body .diplay4 .table_Frequency .table_tab .table_nr table").append("<tr id='trtd" + tr_length + "'>" + $("#trtd1").html() + "</tr>");
    });
};
// 物种输入查询 --- 模糊查询
ZWdataYFone = function (i) {
    baidusearchinput["control_init"]($("input#text" + i + ""), $("input#hiddentext" + i + ""));
    // baidusearchinput["control_init"]($("input#CBWZMC" + i + ""), $("input#CBWZDM" + i + ""));
    // baidusearchinput["control_init"]($("input#GMWZMC" + i + ""), $("input#GMWZDM" + i + ""));
}

//隐藏保存按钮------
function callJsError() {
    $('.XZ_button_bc').remove('input');
}

function callJsInitPdYfInfo(data) {
    $('#PDNameC').html(data.SAMPLEPLOTNAME);
    $('#PDDm').html(data.SAMPLEPLOTID);
    // $('#PDzgdC').html(data.SAMPLEPLOTNAME);
    // $('#PDpjgdC').html(data.SAMPLEPLOTNAME);
    $('#PDzwqlmcC').html(data.ZWQL);
    $('#PDwdC').html(data.YDwd);
    $('#PDjdC').html(data.YDjd);
    $('#PDhbC').html(data.HB);
    $('#PDzbC').html(data.ZBLXMC);
    $('#PDlyfsC').html(data.LYFSMC);
    $('#PDlyqdC').html(data.LYQDMC);
    $('#PDdataC').html(data.CJDATA);
    $('#PDjlrC').html(data.JLR);
}
//保存数据
function PDdataYFone (){
    var obj = $("input[name='test']");
    PDoptions = new Array();
    PDoption = new Array();
    for (var i = 0; i < obj.length; i++) {
        if (obj[i].checked) {
            obj[i].value = 1; //PD多选-------选中是1，没选是0
        } else {
            obj[i].value = 0; //PD多选-------选中是1，没选是0
        }
    }
    var PDwzlength = $(".body .diplay4 .table_Frequency .table_left table tbody tr th input[name='wzmc']");
    var attt = new Array();
    PDwzlength.each(function (i, e) {

        if ($(this).val() != "" && $(this).val() != null) {
            var y = i + 1;
            var str = "";
            var PDtrtdlength = $(".body .diplay4 .table_Frequency .table_nr table tbody #trtd" + y + " td");
            var PDval = $(".body .diplay4 .table_Frequency .table_nr table tbody #trtd" + y + " td input[name='test']");
            for (var j = 0; j < PDtrtdlength.length; j++) {
                str += j == PDtrtdlength.length - 1 ? PDval.eq(j).val() : PDval.eq(j).val() + ',';
                PDoption[j] = {
                    PD: $(".body .diplay4 .table_Frequency .table_nr table tbody #trtd" + y + " td input[name='test']").eq(j).val()
                }
                PDoptions[i] = {
                    WZMC: $(".body .diplay4 .table_Frequency .table_left tr th input[name='wzmc']").eq(i).val(),
                    WZDM: $(".body .diplay4 .table_Frequency .table_left tr th input[name='wzdm']").eq(i).val(),
                    PD: str
                }
            }
            attt[i] = str;
        }
    });

    var str = JSON.stringify({
        SAMPLEPLOTNAME:$('#PDNameC').html(),
        SAMPLEPLOTID:$('#PDDm').html(),
        ZGD:$('#PDzgdC').html(),
        PJGD:$('#PDpjgdC').html(),
        ZWQL:$('#PDzwqlmcC').html(),
        YDwd:$('#PDwdC').html(),
        YDjd:$('#PDjdC').html(),
        HB:$('#PDhbC').html(),
        ZBLXMC:$('#PDzbC').html(),
        LYFSMC:$('#PDlyfsC').html(),
        LYQDMC:$('#PDlyqdC').html(),
        CJDATA:$('#PD').html(),
        JLR:$('#PDjlrC').html(),
        wzInfos: PDoptions
    });
    if (window.android != null && typeof (window.android) != "undefined") {
        window.android.callAndroidSaveShowDialog(str);
    } else {
        alert(typeof (window.android));
    }
}
//显示数据
function callJsLocalExistPdYfInfo(data){
    $('#PDNameC').html(data.SAMPLEPLOTNAME);
    $('#PDDm').html(data.SAMPLEPLOTID);
    $('#PDzgdC').html(data.ZGD);
    $('#PDpjgdC').html(data.PJGD);
    $('#PDzwqlmcC').html(data.ZWQL);
    $('#PDwdC').html(data.YDwd);
    $('#PDjdC').html(data.YDjd);
    $('#PDhbC').html(data.HB);
    $('#PDzbC').html(data.ZBLXMC);
    $('#PDlyfsC').html(data.LYFSMC);
    $('#PDlyqdC').html(data.LYQDMC);
    $('#PDdataC').html(data.CJDATA);
    $('#PDjlrC').html(data.JLR);
    if(data.wzInfos.length == 0) return;
    for (var i = 0; i < data.wzInfos.length; i++) {
        $('#text'+(i+1)).val(data.wzInfos[i].WZMC);
        $('#hiddentext'+(i+1)).val(data.wzInfos[i].WZDM);
        var PDinput = data.wzInfos[i].PD.split(',');
        for(var j = 0; j < PDinput.length;j++){
            if(PDinput[j] == 1){
                $('#trtd' + (i + 1) + ' input').eq(j).prop("checked", true);
            }
        }
    }
}